from optparse import OptionParser
from time import localtime, strftime
from setup import setup

problem_extension = "py"

def main():
    parser = OptionParser()
    parser.add_option("-n", "--session-name", dest="session_name",
                      default = strftime("%a%d%b%Y_%H%M%S", localtime()) +
                      str(),
                      help="output-files are named after it, defaults to timestamp")
#    parser.add_option("-q", "--quiet",
#                      action="store_false", dest="verbose", default=True,
#                      help="don't print status messages to stdout")

    (options, args) = parser.parse_args()
    if len(args) > 0:
        problem_name = args[0]
        exec("import " + problem_name)
        problem = eval(problem_name)

        parameters = setup(problem)

        converge(parameters)

        if hasattr(problem, "errorfile"):
            problem.errorfile.close()

    else:
        print "ERROR: Please specify a problem-file."


    # take non-obvious parameters from problem-file
    # provide mechanism for problems to import most structural stuff
    # (via from x import y)


if __name__ == "__main__":
    main()

